package modelo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


/**
 *
 * @author RICARDO
 */

public class DatosConexion {
/*Esta clase sirve para conectar y desconectar con la bbdd*/
    
    static Connection con  = null;
    static Statement  st   = null;  
    static ResultSet  res  = null; 
    static String     sql  = null;
    private static final String DBH = "jdbc:hsqldb:mem:memoriadb";
    boolean status;
    int i;
    
    public DatosConexion(){
        loadHSQLDB();
        connectDB();
        //createStatement();
    }
    
        public static void loadHSQLDB()
    {
        System.out.println("* Starting...");
        try
        {
            Class.forName("org.hsqldb.jdbcDriver"); //Cargar HSQLDB driver
            System.out.println("* Cargando HSQLDB driver...");
        } 
        catch(Exception e)
        {  
            System.err.println("ERROR: fallo la carga HSQLDB JDBC driver.");
            e.printStackTrace();
            return;  
        } 
    }
    private static void connectDB()
    {
        try
        {  //Conectar a la base de datos o crear si no existe
            con = DriverManager.getConnection(DBH); 
            System.out.println("* Creando conexion HSQLDB...");
        }
        catch(Exception e)
        {
            System.err.println("Error: " + e.getMessage());
            return;
        }
    }
 private static void createStatement()
    
    {
        try
        {
            st  = con.createStatement(); 
        }
        catch (Exception e)
        {  
            System.err.println("Error: createStatement: " + e.getMessage());   
            return;
        }
    }
/*
    public Statement getConexion() {
         try
        {
            st  = con.createStatement(); 
        }
        catch (Exception e)
        {  
            System.err.println("Error: createStatement: " + e.getMessage());   
           
        }
        return st;
    }
    * */
    public Statement cogerStatement(){
        try
        {
            st  = con.createStatement(); 
        }
        catch (Exception e)
        {  
            System.err.println("Error: createStatement: " + e.getMessage());   
           
        }
        return st;
    }
}